package com.weiyun.service.impl;

import com.weiyun.mapper.DeliveryAddressMapper;
import com.weiyun.mapper.UserMapper;
import com.weiyun.pojo.DeliveryAddress;
import com.weiyun.pojo.User;
import com.weiyun.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/***
 *   @Author:weiyun
 *
 */
@Service
public class DeliveryAddressServiceImpl implements DeliveryAddressService {
    @Autowired
    private DeliveryAddressMapper deliveryAddressMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId) {
        try {
            List<DeliveryAddress> deliveryAddresses = deliveryAddressMapper.listDeliveryAddressByUserId(userId);
            return deliveryAddresses;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int saveDeliveryAddress(DeliveryAddress deliveryAddress) {
        try {
            return deliveryAddressMapper.saveDeliveryAddress(deliveryAddress);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int removeDeliveryAddress(Integer daId) {
        try {
            return deliveryAddressMapper.removeDeliveryAddress(daId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public DeliveryAddress getDeliveryAddressById(User userId) {
        try {
            return deliveryAddressMapper.getDeliveryAddressById(userId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int updateDeliveryAddress(DeliveryAddress deliveryAddress) {

        try {
            int i = deliveryAddressMapper.updateDeliveryAddress(deliveryAddress);
            return i;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
